package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.elasticsearch.pojo.dto.DeleteDTO;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.domain.entity.PriorityUpdateEntity;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.domain.dao.ClueAutoAllocationDao;
import com.xbongbong.saas.domain.entity.ClueAutoAllocationEntity;
import com.xbongbong.saas.domain.entity.PublicGroupSeniorEntity;
import com.xbongbong.saas.model.ClueAutoAllocationModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author long
 * @version v1.0
 * @date 2020/12/16 13:50
 * @since v1.0
 */
@Service("clueAutoAllocationModel")
public class ClueAutoAllocationModelImpl implements ClueAutoAllocationModel {
    @Resource
    private ClueAutoAllocationDao clueAutoAllocationDao;

    @Override
    public Integer insert(ClueAutoAllocationEntity entity) throws XbbException {
        return clueAutoAllocationDao.insert(entity);
    }

    @Override
    public Integer update(ClueAutoAllocationEntity entity) throws XbbException {
        return clueAutoAllocationDao.update(entity);
    }

    @Override
    public Integer updateBatchSursplus(List<ClueAutoAllocationEntity> list, String corpid) throws XbbException {
        return clueAutoAllocationDao.updateBatchSursplus(list, corpid);
    }

    @Override
    public void insertBatch(List<ClueAutoAllocationEntity> list) {
        list.forEach(item -> {
            long now = DateUtil.getInt();
            item.setAddTime(now);
            item.setUpdateTime(now);
            item.setDel(BasicConstant.ZERO);
        });
        clueAutoAllocationDao.insertBatch(list);
    }

    @Override
    public List findEntitys(Map<String, Object> param) {
        return clueAutoAllocationDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return clueAutoAllocationDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public void sort(List<PriorityUpdateEntity> entities, String corpid) {
        clueAutoAllocationDao.sort(entities, corpid);
    }

    @Override
    public ClueAutoAllocationEntity getByKey(Long key, String corpid) {
        return clueAutoAllocationDao.getByKey(key, corpid);
    }

    @Override
    public Integer deleteByKey(Long key, String corpid) throws XbbException {
        return clueAutoAllocationDao.deleteByKey(key,corpid);
    }

    @Override
    public Integer updateDelByModelType(Integer del, String corpid, Integer modelType) throws XbbException {
        return clueAutoAllocationDao.updateDelByModelType(del,corpid,modelType);
    }

    @Override
    public Integer save(ClueAutoAllocationEntity clueAutoAllocationEntity) throws XbbException {
        Integer result;
        if (Objects.isNull(clueAutoAllocationEntity.getId())) {
            result = insert(clueAutoAllocationEntity);
        } else {
            result = update(clueAutoAllocationEntity);
        }
        return result;
    }
}
